import requests
import time
from chaojiying import *


headers = {
    'Cookie': 'JSESSIONID=FE285C28B02C6738ACA3B8513307C99B',
    'Host': 'kzp.mof.gov.cn',
    'Referer': 'http://kzp.mof.gov.cn/cjcx/1_b4036a022596202.jsp',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'
}

def getCode():
    timestamp = int(time.time() * 100)
    url = 'http://kzp.mof.gov.cn/cjcx/img.jsp?timestamp={}'.format(timestamp)
    response = requests.get(url=url,headers=headers)

    with open('code.jpg','wb') as f:
        f.write(response.content)

    chaojiying_client = Chaojiying_Client('chenzhigang', 'chen456478', '96001')
    im = open('code.jpg', 'rb').read()
    print(chaojiying_client.PostPic(im, 1902)['pic_str'])
    return chaojiying_client.PostPic(im, 1902)['pic_str']

if __name__ == '__main__':
    getCode()